package utils;

import java.util.ArrayList;
import java.util.List;

import org.ejml.simple.SimpleMatrix;

public final class Summarizer {
   
   public static void printTopN(final SimpleMatrix V, final List<String> wordList, final int n, final int d) {
      System.out.printf("Document %d\n", d);
      
      final ArrayList<Integer> topNRows = getTopNRows(V, d, n);
      
      for (int i = 0; i < topNRows.size(); i++) {
         System.out.printf("%d. %s : %f\n", i + 1, wordList.get(topNRows.get(i)), V.get(topNRows.get(i), d));
      }
   }
   
   public static ArrayList<Integer> getTopNRows(final SimpleMatrix V, final int doc, final int n) {
      int currentMaxNdx = 0;
      final ArrayList<Integer> indicesTaken = new ArrayList<Integer>();
      
      for (int nthLargest = 1; nthLargest <= n; nthLargest++) {
         currentMaxNdx = -1;
         double currentMax = -1;
         for (int currentRow = 0; currentRow < V.numRows(); currentRow++) {
            if (!indicesTaken.contains(currentRow) && currentMax < V.get(currentRow, doc)) {
               currentMaxNdx = currentRow;
               currentMax = V.get(currentRow, doc);
            }
         }
         indicesTaken.add(currentMaxNdx);
      }
      
      return indicesTaken;
   }
   
}
